package talk.Utils;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.talk.debby.talk.R;

import java.util.ArrayList;
import java.util.List;

import talk.Bean.Blank;
import talk.Bean.Choice;
import talk.dapter.ChoiceAdapter;
import talk.listener.BlankListener;
import talk.listener.ChoiceListener;

import static com.talk.debby.talk.R.id.et_answer;

/**
 * Created by debby on 2018/5/31.
 * 描述:
 */

public class ChoiceUtil {


    public static View addView(Activity activity, Choice choice, ChoiceListener listener) {
        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_choice, null);
        TextView tv_question = (TextView) view.findViewById(R.id.tv_question);
        RecyclerView rv_option = (RecyclerView) view.findViewById(R.id.rv_option);
        rv_option.setLayoutManager(new LinearLayoutManager(activity));
        tv_question.setText(choice.getQuestion());
        ChoiceAdapter adapter = new ChoiceAdapter(activity, choice.getOptionList(), listener);
        rv_option.setAdapter(adapter);
        return view;
    }

    public static View addView1(Activity activity, Blank blank, final BlankListener listener) {
        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_blanks, null);
        TextView tv_question = view.findViewById(R.id.tv_question);
        final EditText et_answer = view.findViewById(R.id.et_answer);
        Button bt_confirm = view.findViewById(R.id.bt_confirm);
        bt_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.confirm(et_answer.getText().toString());
            }
        });

        tv_question.setText(blank.getQuestion());
        return view;
    }

    public static Choice getChoice1() {
        Choice choice = new Choice();
        choice.setQuestion("1、以下五种运动形式中，加速度保持不变的运动是");
        choice.setValue(15);
        choice.setAnswer("（D）抛体运动");
        List<Choice.Option> optionList = new ArrayList<>();


        Choice.Option option1 = new Choice.Option();
        option1.content = "（A）单摆运动";
        option1.isTrue = false;
        optionList.add(option1);

        Choice.Option option2 = new Choice.Option();
        option2.content = "（B）匀速率圆周运动";
        option2.isTrue = false;
        optionList.add(option2);

        Choice.Option option3 = new Choice.Option();
        option3.content = "（C）行星的椭圆轨道运动";
        option3.isTrue = false;
        optionList.add(option3);

        Choice.Option option4 = new Choice.Option();
        option4.content = "（D）抛体运动";
        option4.isTrue = true;
        optionList.add(option4);

        Choice.Option option5 = new Choice.Option();
        option5.content = "（E）圆锥摆运动";
        option5.isTrue = false;
        optionList.add(option5);

        choice.setOptionList(optionList);
        return choice;
    }

    public static Choice getChoice2() {
        Choice choice = new Choice();
        choice.setQuestion("一质量为M、长为L的均匀细棒绕一固定转动轴转动，" +
                "若转轴在距端点1/4处穿过细棒并与细棒垂直，则细棒相对于该转轴的转动惯量为");
        choice.setValue(15);
        choice.setAnswer("（D） 7/48 ml²");
        List<Choice.Option> optionList = new ArrayList<>();


        Choice.Option option1 = new Choice.Option();
        option1.content = "（A） 7/12 ml²";
        option1.isTrue = false;
        optionList.add(option1);

        Choice.Option option2 = new Choice.Option();
        option2.content = "（B） 7/24 ml²";
        option2.isTrue = false;
        optionList.add(option2);

        Choice.Option option3 = new Choice.Option();
        option3.content = "（C） 7/36 ml²";
        option3.isTrue = false;
        optionList.add(option3);

        Choice.Option option4 = new Choice.Option();
        option4.content = "（D） 7/48 ml²";
        option4.isTrue = true;
        optionList.add(option4);

        choice.setOptionList(optionList);
        return choice;
    }

    public static Choice getChoice3() {
        Choice choice = new Choice();
        choice.setQuestion("3、初始状态静止的刚体在一力矩作用下绕定轴转动，当力矩减小时，刚体的");
        choice.setValue(15);
        choice.setAnswer("（B）角速度增加和角加速度减小");
        List<Choice.Option> optionList = new ArrayList<>();


        Choice.Option option1 = new Choice.Option();
        option1.content = "（A）角速度和角加速度都增加";
        option1.isTrue = false;
        optionList.add(option1);

        Choice.Option option2 = new Choice.Option();
        option2.content = "（B）角速度增加和角加速度减小";
        option2.isTrue = true;
        optionList.add(option2);

        Choice.Option option3 = new Choice.Option();
        option3.content = "（C）角速度减小和角加速度增加";
        option3.isTrue = false;
        optionList.add(option3);

        Choice.Option option4 = new Choice.Option();
        option4.content = "（D）角速度和角加速度都减小";
        option4.isTrue = false;
        optionList.add(option4);

        choice.setOptionList(optionList);
        return choice;
    }

    public static Choice getChoice4() {
        Choice choice = new Choice();
        choice.setQuestion("4、足球守门员要分别接住来势不同的两个球，一个球在空中无转动地飞来，" +
                "另一个在地面滚来。两个球的质量和前进的速度一样，则守门员接住着两个球所作的功");
        choice.setValue(15);
        choice.setAnswer("（C）第二个球大");
        List<Choice.Option> optionList = new ArrayList<>();


        Choice.Option option1 = new Choice.Option();
        option1.content = "（A）相同";
        option1.isTrue = false;
        optionList.add(option1);

        Choice.Option option2 = new Choice.Option();
        option2.content = "（B）第一个球大";
        option2.isTrue = false;
        optionList.add(option2);

        Choice.Option option3 = new Choice.Option();
        option3.content = "（C）第二个球大";
        option3.isTrue = true;
        optionList.add(option3);

        Choice.Option option4 = new Choice.Option();
        option4.content = "（D）无法判断";
        option4.isTrue = false;
        optionList.add(option4);

        choice.setOptionList(optionList);
        return choice;
    }

    public static Blank addBlank1() {
        Blank blank = new Blank();
        blank.setQuestion("1、一个以恒定角加速度转动的圆盘，" +
                "如果在某一时刻的角速度为ω1=20πrad/s，再转50转后角速度为ω2=30πrad/s，" +
                "则转过上述50转所需的时间为?");
        blank.setValue(20);
        blank.setAnswer("4s");
        return blank;
    }

    public static Blank addBlank2() {
        Blank blank = new Blank();
        blank.setQuestion("一质量为M，半径为R的定滑轮，对水平轴的转动惯量J=MR²/2，在滑轮上绕一细绳，" +
                "绳的下端挂一物体，绳的质量可以忽略且不能伸长，滑轮与轴承间无摩擦，" +
                "物体下落的加速度为a，则绳中的张力为T=？");
        blank.setValue(20);
        blank.setAnswer("1/2Ma");
        return blank;
    }
}
